﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
using Telerik.WebControls;
using System.Data.OleDb;

public partial class sysadmin_UserManager_UserExportByExcel :System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            
        }
    }
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
        {
            string url = PowerCreator.LMS.Web.Config.WebConfig.UPLOAD_DOWNLOAD_FILEPATH;
            string saveFilePath = Server.MapPath(url);

            //如果路径不存在，则创建
            if (System.IO.Directory.Exists(saveFilePath))
            {
                System.IO.Directory.CreateDirectory(saveFilePath);
            }
            if (!saveFilePath.EndsWith("\\"))
                saveFilePath += "\\";

            string fileName = DateTime.Now.ToString("yyyyMMddHHmm") + file.GetExtension();
            //保存
            lbl_FilePath.Text = saveFilePath + fileName;
            file.SaveAs(saveFilePath + fileName, true);
        }
    }
    protected void btn_Query_Click(object sender, EventArgs e)
    {
        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lbl_FilePath.Text + ";Extended Properties=Excel 8.0;";
        string cmd = "select * from [Sheet1$]";
        OleDbDataAdapter da = new OleDbDataAdapter(cmd,strConn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gv_User.DataSource = ds.Tables[0];
        gv_User.DataBind();
        ArrayList columnsList = new ArrayList();
        for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
        {
            columnsList.Add(ds.Tables[0].Columns[i].ColumnName);
        }
        ddl_TableColumn.DataSource = columnsList;
        ddl_TableColumn.DataBind();
    }

    private void BinderExcelTableColumns()
    { 
        
    }
}
